import java.util.*;

public class Solution {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- != 0) {
            int n = in.nextInt(), k = in.nextInt();
            char[] ch = in.next().toCharArray();

            int ret = 0;
            for (int i = 0; i < ch.length; i++) {
                if (ch[i] == 'L') {
                    ret -= 1;
                }
                if (i - 1 >= 0 && i - 2 >= 0 && ch[i - 1] == 'W' && ch[i - 2] == 'W') {
                    ret += k;
                } else {
                    ret++;
                }
            }
            System.out.println(ret);
        }
    }

    public int maxLength(int[] arr){
        int[] hash = new int[100010];
        int left = 0, right = 0, n = arr.length;
        int ret = 0;
        while(right < n){
            hash[arr[right]]++;
            while(hash[arr[right]] > 1){
                hash[arr[left]]--;
                left++;
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        return ret;
    }
}
